#ifndef MATH_H_
#define MATH_H_
#include <iostream>
#include <vector>
#include <string>
#include <gmp.h>
#include <cmath>
#include <gmpxx.h>
#include <random>
#include <time.h>
#include "prime.hpp"

using namespace std;
/*
 * 数学工具类
 */
class Math{
public:
	// 求a的e次方模mod的值
	static mpz_class power_mod(mpz_class a, mpz_class e, mpz_class mod){
		mpz_class p = 1;
		while(e){
			if((e % 2) == 1){
				p = (p * a) % mod;
			}
			a = (a * a) % mod;
			e >>= 1;
		}
		return p;
	}

	static mpz_class random_num_base_ten(int base_ten_len){
		default_random_engine e; 
		unsigned ts = (unsigned)time(0);
		e.seed(ts);
		uniform_int_distribution<unsigned> u(0, 9);
		u(e);
		string str;
		unsigned num;
		for(int i = 1; i <= base_ten_len; i++){
			if(i == 1){
				uniform_int_distribution<unsigned> ufirst(1, 9);
				num = ufirst(e);
			}else{
				num = u(e);
			}
			str += string(to_string(num));
		}
		return mpz_class(str);
	}

	/*
	 * 二进制长度位bit_len的随机数
	 */
	static mpz_class random_num(int bit_len){
		return random_num_base_ten(ceil(bit_len * log10(2)));
	}
};

#endif
